<html>
<head>
<title>用户列表</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css"
	href="../easyUI/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="../easyUI/themes/icon.css">
<link rel="stylesheet" type="text/css" href="../demo.css">
<!-- <script type="text/javascript" src="../easyUI/jquery.min.js"></script> -->
<!-- <script type="text/javascript" src="../easyUI/jquery.easyui.min.js"></script> -->
<script language="javascript" src="../script/jquery.js"></script>
<script language="javascript" src="../script/pageCommon.js"
	charset="utf-8"></script>
<script language="javascript" src="../script/PageUtils.js"
	charset="utf-8"></script>
<script language="javascript" src="../script/DemoData.js"
	charset="utf-8"></script>
<script language="javascript" src="../script/DataShowManager.js"
	charset="utf-8"></script>
<link type="text/css" rel="stylesheet"
	href="../style/blue/pageCommon.css" />
<link rel="stylesheet" type="text/css"
	href="../easyUI/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="../easyUI/themes/icon.css">
<link rel="stylesheet" type="text/css" href="../demo.css">
<script type="text/javascript" src="../easyUI/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="../easyUI/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="../easyUI/plugins/jquery.datagrid.js"></script>
<script type="text/javascript" src="../zTree_v3/js/jquery.ztree.core.js"></script>

<script type="text/javascript"
	src="../zTree_v3/js/jquery.ztree.all.min.js"></script>
<link rel="stylesheet" href="../zTree_v3/css/zTreeStyle/zTreeStyle.css"
	type="text/css">
<link rel="stylesheet" href="../zTree_v3/css/demo.css" type="text/css">

<script type="text/javascript">
    </script>
</head>

<body>

	<div id="Title_bar" style="float:top">
		<div id="Title_bar_Head">
			<div id="Title_Head"></div>
			<div id="Title">
				<!--页面标题-->
				<img border="0" width="13" height="13"
					src="../style/images/title_arrow.gif" /> 权限管理
			</div>
			<div id="Title_End"></div>
		</div>
	</div>

	<div class="content_wrap">
		<div id="role" class="right"></div>
		<div class="">
			<ul id="tree" class="ztree"></ul>
		</div>
		
		<div><a href="javascript:prov();">授权</a></div>
	</div>




	<script type="text/javascript">
		$(document).ready(function() {
			$("#role").datagrid({
				url : 'getAllRole',
				width : "500",
				fitColumns : true,
				singleSelect:true,
				onClickRow:clickRow,
				pagination:true,
				pageList:[2,3,5],
				striped:true,
				loadMsg:'加载中',
				columns : [ [
					
					{
						field : 'id',
						title : 'id',
						width : 100,
						align : 'center',
						hidden : true
					},
	
					{
						field : 'name',
						title : '角色名',
						width : 200,
						align : 'center'
					},
					{
						field : 'state',
						title : '状态',
						width : 100,
						align : 'center',
						formatter:function(value,row,index){
							if(value==1){
								return '可用';
							}
							else{
								return '不可用';
							}
						}
					},
					{
						field : 'action',
						title : '操作',
						align : 'center',
						fixed : true,
						width : 100,
						formatter:function (value,row,index){
							return "<a href='#' >作废<a/>";
						}
					}
				] ]
			});
		});
	
		$(document).ready(function() {
			var setting = {
					treeId:"tree",
				view : {
					dblClickExpand : false, //双击节点时，是否自动展开父节点的标识
					showLine : true, //是否显示节点之间的连线
					fontCss : {
						'color' : 'black',
						'font-weight' : 'bold'
					}, //字体样式函数
					selectedMulti : true //设置是否允许同时选中多个节点
				},
				check:{
					enable:true,
					chkboxType: { "Y": "ps", "N": "ps" } 
				},
				data : {
					simpleData : { //简单数据模式
						enable : true,
						idKey : "id",
						pIdKey : "pid",
						rootPId : null
					}
				},
				
			};
	
			$.post("getztreeProv", null, function(data, textStatus, req) {
				zTreeObj = $.fn.zTree.init($("#tree"), setting, data);
			})
	
		})
		
		function prov(){
				var treeObj = $.fn.zTree.getZTreeObj("tree");
				var menus = treeObj.getCheckedNodes(true);
				var role = $("#role").datagrid("getSelected");
				//alert(role.id);
				 var mens = "";
				for(var i=0;i<menus.length;i++){
					mens += menus[i].id+",";
				} 
				//alert(menus);
				$.post("prov",{"menus":mens,"role":role.id},function(data,textStatus,req){
						$.messager.alert("提示信息","授权成功","info");
				})
			};
	function clickRow(index,data){
		//alert(data.id);
			var treeObj = $.fn.zTree.getZTreeObj("tree");
			var nodes = treeObj.getNodes(); //只获取了根节点
			var mycars = new Array();
			for(var i=0;i<nodes.length;i++){
				var nodesc = treeObj.getNodesByParam("pid", nodes[i].id, null); //根据根节点获取所有的子节点放入数组中
				mycars[i]=nodesc;
			}
			mycars[mycars.length] = nodes;
			treeObj.checkAllNodes(false);  //先全部取消选择，防止缓存问题
		$.post("provshow",{"role":data.id},function(data){
		for(var a = 0;a<mycars.length;a++){   //遍历所有的节点如果和当前角色的授权节点相同，就勾选
				var nodess = mycars[a];
			for(var i=0;i<nodess.length;i++){
			//alert(nodess[i].id)
				for(var j=0;j<data.length;j++){
					if(nodess[i].id==data[j]){
					//alert(true)
						treeObj.checkNode(nodess[i],true,false,false);  //1.节点 2.是否选中 3.是否联动 4.是否有返回动作
					}
				}
			}
			}
		})
	}
		
	</script>
</body>

</html>
